package com.stars.controller.mygenerate;

import com.stars.entity.dto.mygenerate.CgConfigDTO;
import com.stars.services.mygenerate.CgConfigConfigService;
import com.stars.entity.mygenerate.CgConfigEntity;
import com.stars.services.mygenerate.CgConfigAccessService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import com.stars.common.annotation.Log;
import com.stars.common.base.BaseMsg;
import com.stars.common.ObjectCopyUtils;
import com.stars.common.base.BaseConstant;
import com.stars.common.base.ResultMsg;
import com.stars.controller.BaseController;
import com.stars.common.enums.OperationType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletRequest;
import com.stars.common.valid.AddView;
import com.stars.common.valid.UpdateView;
import com.github.pagehelper.PageInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
/**
 * @Title: 我的代码配制 mybatis dao
 * @author dj
 * @date 2019-10-30
 * @version V1.0
 *
 */
@Slf4j
@RestController
@RequestMapping("/cgConfigCtl")
@Api(tags ="我的代码配制")
public class CgConfigCtl extends BaseController{
   @Autowired
   private CgConfigAccessService  cgConfigAccessServiceImpl;
   @Autowired
   private CgConfigConfigService  cgConfigConfigServiceImpl;

   /**
   *  分页查询
   * @param pageNum 起始页
   * @param pageSize 大小
   * @return 分页数据
   * @throws Exception
   */
   @GetMapping("/pageList")
   @ApiOperation(value = "我的代码配制"+BaseMsg.MODULAR_PAGE,notes ="我的代码配制"+ BaseMsg.MODULAR_PAGE)
   @Log(detail = "我的代码配制"+ BaseMsg.MODULAR_PAGE,operationType = OperationType.SELECT)
   public PageInfo<CgConfigDTO> pageCgConfigList(Integer pageNum, Integer pageSize, CgConfigDTO dto,HttpServletRequest request) throws Exception{
  
        return cgConfigAccessServiceImpl.pageList(pageNum,pageSize,dto);

   }

    /**
    * 保存
    * @param entityName
    * @return 成功失败
    * @throws Exception
    */
    @PostMapping(value = "/add")
    @ApiOperation(value = "我的代码配制"+ BaseMsg.MODULAR_ADD,notes = "我的代码配制"+BaseMsg.MODULAR_ADD)
    @Log(detail = "我的代码配制"+BaseMsg.MODULAR_ADD,operationType = OperationType.INSERT)
    public ResultMsg addCgConfig(@Validated({AddView.class}) CgConfigEntity entityName,HttpServletRequest request) throws Exception{
        setAddBase(entityName,request,null);
        return cgConfigConfigServiceImpl.insertSelective(entityName);
    }
    /**
    * 更新
    * @param updateEntityDto
    * @return 成功失败
    * @throws Exception
    */
    @PostMapping(value = "/update")
    @ApiOperation(value = "我的代码配制"+ BaseMsg.MODULAR_UPDATE,notes = "我的代码配制"+ BaseMsg.MODULAR_ADD)
    @Log(detail = "我的代码配制"+ BaseMsg.MODULAR_UPDATE,operationType = OperationType.UPDATE)
    public ResultMsg updateCgConfig(@Validated({UpdateView.class}) CgConfigEntity updateEntityDto,HttpServletRequest request) throws Exception{
        CgConfigEntity entity = cgConfigAccessServiceImpl.selectById(updateEntityDto.getId());
        ObjectCopyUtils.copyPropertiesIf(updateEntityDto,entity, BaseConstant.UPDATE);
        setUpdateBase(entity,request);
        return cgConfigConfigServiceImpl.updateSelectiveById(entity);
    }

    /**
    * 根据id查询
    * @param id
    * @return 查询对象
    * @throws Exception
    */
    @GetMapping(value = "/findById")
    @ApiOperation(value = "我的代码配制"+ BaseMsg.MODULAR_FIND_ID,notes = "我的代码配制"+BaseMsg.MODULAR_FIND_ID)
    @Log(detail = "我的代码配制"+ BaseMsg.MODULAR_FIND_ID,operationType = OperationType.SELECT)
    public ResultMsg findCgConfigById(String id) throws Exception{
        CgConfigEntity entityName = cgConfigAccessServiceImpl.selectById(id);
         return ResultMsg.success(entityName);
    }

     /**
     * 删除
     * @param ids
     * @return 成功失败
     * @throws Exception
     */
     @PostMapping(value = "/delById")
     @ApiOperation(value = "我的代码配制"+BaseMsg.MODULAR_DEL,notes ="我的代码配制"+BaseMsg.MODULAR_DEL)
     @Log(detail ="我的代码配制"+BaseMsg.MODULAR_DEL,operationType = OperationType.DELETE)
     public ResultMsg delCgConfigById(String ids) throws Exception{
       return cgConfigConfigServiceImpl.deleteByIds(ids.split(BaseConstant.SPOT));
     }

}